(function(e,t,i,a){"use strict";var n;var r=new Map;var s=function(){babelHelpers.createClass(e,null,[{key:"getById",value:function e(t){return r.get(t)||null}}]);function e(){var a=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"container",null);babelHelpers.defineProperty(this,"loaderContainer",null);babelHelpers.defineProperty(this,"addButton",null);babelHelpers.defineProperty(this,"loader",null);babelHelpers.defineProperty(this,"timeout",null);babelHelpers.defineProperty(this,"uploading",false);babelHelpers.defineProperty(this,"onUploaderIsInitedHandler",this.handleOnUploaderIsInited.bind(this));babelHelpers.defineProperty(this,"recalculateWrapperHandler",this.recalculateWrapper.bind(this));this.instanceId=a.instanceId;this.containerId=a.containerId;this.loaderContainerId=a.loaderContainerId;this.settings=a.settings||{};this.disabled=a.disabled||false;if(this.disabled){t.Event.bind(this.getContainer(),"click",(function(e){e.stopPropagation();e.preventDefault()}))}this.addImageHandler=this.addImage.bind(this);this.editImageHandler=this.editImage.bind(this);i.EventEmitter.subscribe("onUploaderIsInited",this.onUploaderIsInitedHandler);r.set(this.instanceId,this)}babelHelpers.createClass(e,[{key:"handleOnUploaderIsInited",value:function e(a){var n=this;var r=a.getCompatData(),s=babelHelpers.slicedToArray(r,2),l=s[0],o=s[1];if(this.instanceId===l){if(this.getPreviews().length>0){t.Dom.addClass(this.getFileWrapper(),"ui-image-input-wrapper")}requestAnimationFrame((function(){n.getLoaderContainer()&&(n.getLoaderContainer().style.display="none");n.getContainer().style.display=""}));i.EventEmitter.subscribe(o,"onFileIsDeleted",this.onFileIsDeletedHandler.bind(this));i.EventEmitter.subscribe(o,"onStart",this.onUploadStartHandler.bind(this));i.EventEmitter.subscribe(o,"onDone",this.onUploadDoneHandler.bind(this));i.EventEmitter.subscribe(o,"onFileCanvasIsLoaded",this.onFileCanvasIsLoadedHandler.bind(this));i.EventEmitter.unsubscribe("onDemandRecalculateWrapper",this.recalculateWrapperHandler);i.EventEmitter.subscribe("onDemandRecalculateWrapper",this.recalculateWrapperHandler)}}},{key:"unsubscribeEvents",value:function e(){i.EventEmitter.unsubscribe("onDemandRecalculateWrapper",this.recalculateWrapperHandler);i.EventEmitter.unsubscribe("onUploaderIsInited",this.onUploaderIsInitedHandler)}},{key:"getInputInstance",value:function e(){return BX.UI.FileInput.getInstance(this.instanceId)}},{key:"getFileInput",value:function e(){return this.getInputInstance().agent.fileInput}},{key:"getContainer",value:function e(){if(!this.container){this.container=document.getElementById(this.containerId);if(!t.Type.isDomNode(this.container)){throw Error("Can't find container with id ".concat(this.containerId))}}return this.container}},{key:"getFileWrapper",value:function e(){if(!this.fileWrapper){this.fileWrapper=this.getContainer().querySelector(".adm-fileinput-wrapper")}return this.fileWrapper}},{key:"getLoaderContainer",value:function e(){if(!this.loaderContainer){this.loaderContainer=document.getElementById(this.loaderContainerId)}return this.loaderContainer}},{key:"getAddButton",value:function e(){if(!this.addButton){this.addButton=this.getContainer().querySelector('[data-role="image-add-button"]')}return this.addButton}},{key:"editImage",value:function e(t){if(t.target===this.getFileInput()){if(t.detail===0){return}else{t.preventDefault()}}var i=this.getInputInstance();var a=i.agent.getItems().items;for(var n in a){if(a.hasOwnProperty(n)){i.frameFlags.active=true;i.frameFiles(n);break}}}},{key:"addImage",value:function e(t){t.preventDefault();t.stopPropagation();this.getFileInput().click()}},{key:"getLoader",value:function e(){if(!this.loader){this.loader=new a.Loader({target:this.getFileWrapper().querySelector(".adm-fileinput-drag-area")})}return this.loader}},{key:"showLoader",value:function e(){this.getLoader().setOptions({size:Math.min(this.getContainer().offsetHeight,this.getContainer().offsetWidth)});this.getLoader().show()}},{key:"hideLoader",value:function e(){this.getLoader().hide()}},{key:"onFileIsDeletedHandler",value:function e(){var t=this;this.timeout=clearTimeout(this.timeout);this.timeout=setTimeout((function(){t.hideLoader();t.recalculateWrapper()}),100)}},{key:"onUploadStartHandler",value:function e(t){var i=this;var a=t.getCompatData(),n=babelHelpers.slicedToArray(a,1),r=n[0];if(r){this.uploading=true}clearTimeout(this.timeout);this.timeout=setTimeout((function(){i.showLoader();i.recalculateWrapper()}),100)}},{key:"onUploadDoneHandler",value:function e(t){var i=this;var a=t.getCompatData(),n=babelHelpers.slicedToArray(a,1),r=n[0];if(r){this.uploading=false;this.timeout=clearTimeout(this.timeout);requestAnimationFrame((function(){i.hideLoader();i.recalculateWrapper()}))}}},{key:"onFileCanvasIsLoadedHandler",value:function e(){var t=this;if(this.timeout&&!this.uploading){this.uploading=false;this.timeout=clearTimeout(this.timeout);requestAnimationFrame((function(){t.hideLoader();t.recalculateWrapper()}))}}},{key:"isMultipleInput",value:function e(){return this.getInputInstance().uploadParams.maxCount!==1}},{key:"buildShadowElement",value:function e(i){if(i.offsetParent===null){return}var a=i.querySelector("div.ui-image-item-shadow");if(!a){a=t.Tag.render(n||(n=babelHelpers.taggedTemplateLiteral(['<div class="ui-image-item-shadow"></div>'])));t.Dom.prepend(a,i)}var r=i.querySelector("canvas");if(r){var s=4;a.style.height=r.offsetHeight+"px";a.style.width=r.offsetWidth-s+"px";i.querySelector(".adm-fileinput-item-preview").style.height=r.offsetHeight+"px";i.closest(".adm-fileinput-item-wrapper").style.height=r.offsetHeight+"px"}}},{key:"getPreviews",value:function e(){return this.getFileWrapper().querySelectorAll(".adm-fileinput-item")}},{key:"recalculateWrapper",value:function e(){var i=this.getFileWrapper();var a=this.getPreviews();var n=Math.min(a.length,3);if(n){this.buildShadowElement(a[0]);t.Dom.addClass(i,"ui-image-input-wrapper");this.getFileInput().style.display="none";t.Event.unbind(i,"click",this.editImageHandler);t.Event.bind(i,"click",this.editImageHandler);if(this.isMultipleInput()){this.getAddButton().style.display="";t.Event.unbindAll(this.getAddButton());t.Event.bind(this.getAddButton(),"click",this.addImageHandler)}}else{t.Dom.removeClass(i,"ui-image-input-wrapper");this.getFileInput().style.display="";t.Event.unbind(i,"click",this.editImageHandler);if(this.isMultipleInput()){this.getAddButton().style.display="none";t.Event.unbindAll(this.getAddButton())}}switch(n){case 3:t.Dom.addClass(i,"ui-image-input-wrapper-multiple");t.Dom.removeClass(i,"ui-image-input-wrapper-double");break;case 2:t.Dom.addClass(i,"ui-image-input-wrapper-double");t.Dom.removeClass(i,"ui-image-input-wrapper-multiple");break;default:t.Dom.removeClass(i,"ui-image-input-wrapper-double");t.Dom.removeClass(i,"ui-image-input-wrapper-multiple");break}}}]);return e}();t.Reflection.namespace("BX.UI").ImageInput=s})(this.window=this.window||{},BX,BX.Event,BX);
//# sourceMappingURL=script.map.js